<?php namespace App\Admin\Access\Role\Criterias;

use App\Core\Repository\Criteria;
use App\Core\Repository\Repository;
use Auth;

class HasPermission extends Criteria{

    public function apply(Repository $repository){
        parent::apply($repository);
        $user = Auth::user();
		if(!$user->isAdmin()){
			$field = $this->formatField($this->model, 'role_id');
            $this->query->where($field, 'like', $user->role->role_id.'%')->where($field, '!=', $user->role->role_id);
		}
    }
}